package view
{
	import com.common.Color;
	import com.util.AlignUtil;
	import com.util.MakeChildrenUtil;
	
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import xm.components.button.SWCButton;
	import xm.components.text.TruncateTextField;
	import xm.core.XMSprite;
	import xm.view.ViewDefault;
	
	/**
	 * <br> 클래스 설명 : </br>
	 * @author 강석민
	 */	
	public class View01_XMSprite extends ViewDefault
	{
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		private var xmsList : Vector.<XMSprite>;
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * constructor 
		 */	
		public function View01_XMSprite()
		{
		}
		
		/**
		 * commitProperties
		 */		
		override public function commitProperties():void
		{
			super.commitProperties();
		}
		
		/**
		 * updateDisplayList
		 */		
		override public function updateDisplayList( enforce : Boolean = false ):void
		{
			super.updateDisplayList(enforce);
			
			var len : int = xmsList.length;
			var i : int = 0;
			while ( i < len )
			{
				AlignUtil["simpleAlign"+(i+1)]( xmsList[i], this.availableWidth, this.availableHeight );
				++i;
			}
			
		}
		
		//-----------------------------------------------------------------------------------
		// life cycle functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * createChildren
		 */		
		override public function createChildren():void
		{
			super.createChildren();
			xmsList = new Vector.<XMSprite>();
			//============================================================
			//						액션바
			//============================================================
			//네비게이션컨텐츠
			var navigationBtn : SWCButton = MakeChildrenUtil.makeSwcBtn( new BTN_PREV );
			this.navigationContent = MakeChildrenUtil.makeNavigationContent( navigationBtn );
			//타이틀 컨텐츠
			var titleTextField : TextField = MakeChildrenUtil.makeTextField( "View01_XMSprite", Color.WHITE, 20 );
			this.titleContent  = MakeChildrenUtil.makeTitleContent( titleTextField );
			//액션컨텐츠
			var actionBtn : SWCButton = MakeChildrenUtil.makeSwcBtn( new BTN_NEXT ); 
			this.actionContent = MakeChildrenUtil.makeActionContent( actionBtn );
			actionBtn.addEventListener(MouseEvent.CLICK , onActionBtnClick );
			//============================================================
			//						화면구성
			//============================================================
			var xms : XMSprite,tf : TextField;
			var len : int = 9;
			var i : int = 0;
			while ( i < len )
			{
				tf = MakeChildrenUtil.makeTextField( (i+1).toString(), 0xffffff );
				xms = MakeChildrenUtil.makeXMSprite( tf, 100, 100, Color.ORANGE );
				
				xms.padding = [10, 10, 10, 10];
				xms.borderAlpha = [1, 1, 1, 1];
				xms.borderThickness = [2, 2, 2, 2];
				xms.borderColor = [Color.RED, Color.BLUE, Color.GREEN, Color.WHITE];
				xms.invalidateDisplayList();
				
				
				xmsList.push( xms );
				AlignUtil.simpleAlign5( tf, xms.width, xms.height );
				this.addChild( xms );
				++i;
			}
			
		}
		
		/**
		 * createComplete
		 */		
		override public function creationComplete():void
		{
			super.creationComplete();
		}
		
		/**
		 * add
		 */		
		override public function add():void
		{
			super.add();
		}
		
		/**
		 * startAddTransition : add 완료 후 transition 이 있으면 화면전환효과를 실행한다.
		 */		
		override public function startAddTransition():void
		{
			super.startAddTransition();
		}
		
		/**
		 * startAddTransition 완료.
		 */		
		override public function endAddTransition():void
		{
			super.endAddTransition();
		}
		
		/**
		 * startRemoveTransition : remove 하기 전 transition 이 있으면 화면전환효과를 실행한다.
		 */		
		override public function startRemoveTransition():void
		{
			super.startRemoveTransition();
		}
		
		/**
		 * startRemoveTransition 완료.
		 */		
		override public function endRemoveTransition():void
		{
			super.endRemoveTransition();
		}
		
		/**
		 * remove
		 */		
		override public function remove():void
		{
			super.remove();
		}
		
		/**
		 * destroy
		 */		
		override public function destroy():void
		{
			super.destroy();
			xmsList = null;
		}
		
		//-----------------------------------------------------------------------------------
		// setter / getter
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// protected functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// internal functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		/**
		 *
		 */
		private function onActionBtnClick(e:MouseEvent):void
		{
			this.navigator.add( View02_Radio );
		}
		
		
	}
}